﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HotSpot.Silverlight.Web.DomainServices;
using HotSpot.Silverlight.Web.DAL;

namespace HotSpot.Silverlight
{
	public partial class HotSpotMainPage : UserControl
	{
		public HotSpotMainPage()
		{	
			InitializeComponent();
			ArrowEffect.Begin();
            FaderGlobe.Begin();

            Loaded += new RoutedEventHandler(HotSpotMainPage_Loaded);
		}

        void HotSpotMainPage_Loaded(object sender, RoutedEventArgs e)
        {
            HotSpotDomainContext hsContext = new HotSpotDomainContext();
            cmbCountry.ItemsSource = hsContext.Countries;
            hsContext.Load(hsContext.GetCountryQuery());
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.ScrollViewer mp = 
                (System.Windows.Controls.ScrollViewer)App.Current.RootVisual;
            
            #region Search criteria
            int idCountry = 0;
            if (cmbCountry.SelectedItem != null)
                idCountry = (cmbCountry.SelectedItem as Country).Id;
            int idTown = 0;
            if (cmbTown.SelectedItem != null)
                idTown = (cmbTown.SelectedItem as Town).Id;
            int stars = int.Parse(upDownStars.Value.ToString());
            bool detaliedSearchTags = searchExpand.IsExpanded;
            bool allowPets = Pets.IsChecked ?? false;
            bool restaurant = Restaurant.IsChecked ?? false;
            bool spa = Spa.IsChecked ?? false;
            bool pool = Pool.IsChecked ?? false;
            bool parking = Parking.IsChecked ?? false;
            bool conferenceRoom = ConferenceRoom.IsChecked ?? false;
            #endregion

            Uri target = 
                new Uri(
                    "/HSAccommodation" + 
                    "?searchText=" + txtSearch.Text + 
                    "&idCountry=" + idCountry +
                    "&idTown=" + idTown + 
                    "&stars=" + stars + 
                    "&detaliedSearchTags=" + detaliedSearchTags + 
                    "&allowPets=" + allowPets + 
                    "&restaurant=" + restaurant + 
                    "&spa=" + spa + 
                    "&pool=" + pool + 
                    "&parking=" + parking + 
                    "&conferenceRoom=" + conferenceRoom,
                    UriKind.Relative);
            (mp.Content as HotSpotMainPage).ContentFrame.Navigate(target);
        }

        private void cmbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            HotSpotDomainContext hsContext = new HotSpotDomainContext();
            cmbTown.ItemsSource = hsContext.Towns;
            hsContext.Load(hsContext.GetTownByIdCountryQuery((cmbCountry.SelectedItem as Country).Id));
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            lblLogin20.Opacity = 1;
        }	
	}
}